/*
 * Powered By [leyvi]
 * Since 2014 - 2015
 */


var member = {};
var common = require('../../utils/commonUtils');
//db转换成model
member.dbConvertModel = function(db){
	var member = {}; 
	if(common.isNotBlank(db.id)) member.id = db.id;	
	if(typeof db.username != "undefined") member.username = db.username;
	if(typeof db.password != "undefined") member.password = db.password;
	if(typeof db.phone != "undefined") member.phone = db.phone;
	if(typeof db.email != "undefined") member.email = db.email;
	if(typeof db.head_img_url != "undefined") member.headImgUrl = db.head_img_url;
	if(common.isNotBlank(db.fans_num)) member.fansNum = db.fans_num;	
	if(common.isNotBlank(db.create_time)){
		member.createTime = db.create_time;
		member.createTimeStr = db.create_time.format('yyyy-MM-dd hh:mm');
	} 		
	if(common.isNotBlank(db.update_time)){
		member.updateTime = db.update_time;
		member.updateTimeStr = db.update_time.format('yyyy-MM-dd hh:mm');
	} 		
	if(common.isNotBlank(db.bak1)) member.bak1 = db.bak1;	
	if(common.isNotBlank(db.bak2)) member.bak2 = db.bak2;	
	if(common.isNotBlank(db.bak3)) member.bak3 = db.bak3;	
	if(typeof db.bak4 != "undefined") member.bak4 = db.bak4;
	if(typeof db.bak5 != "undefined") member.bak5 = db.bak5;
	return member;
};

//model转换成db
member.modelConvertDb = function(obj){
	var db = {}; 
	if(common.isNotBlank(obj.id)) db.id = obj.id;
	if(typeof obj.username != "undefined") db.username = obj.username;
	if(typeof obj.password != "undefined") db.password = obj.password;
	if(typeof obj.phone != "undefined") db.phone = obj.phone;
	if(typeof obj.email != "undefined") db.email = obj.email;
	if(typeof obj.headImgUrl != "undefined") db.head_img_url = obj.headImgUrl;
	if(common.isNotBlank(obj.fansNum)) db.fans_num = obj.fansNum;
	if(common.isNotBlank(obj.createTime)) db.create_time = obj.createTime;
	if(common.isNotBlank(obj.updateTime)) db.update_time = obj.updateTime;
	if(common.isNotBlank(obj.bak1)) db.bak1 = obj.bak1;
	if(common.isNotBlank(obj.bak2)) db.bak2 = obj.bak2;
	if(common.isNotBlank(obj.bak3)) db.bak3 = obj.bak3;
	if(typeof obj.bak4 != "undefined") db.bak4 = obj.bak4;
	if(typeof obj.bak5 != "undefined") db.bak5 = obj.bak5;
	return db;
};

member.initPostReq = function(req){
	var member = {};
	if(req.body.id != undefined){
		(typeof req.body.id != 'string') ? (member.id = req.body.id) : (member.id = req.body.id.trim());
	}
	if(req.body.username != undefined){
		(typeof req.body.username != 'string') ? (member.username = req.body.username) : (member.username = req.body.username.trim());
	}
	if(req.body.password != undefined){
		(typeof req.body.password != 'string') ? (member.password = req.body.password) : (member.password = req.body.password.trim());
	}
	if(req.body.phone != undefined){
		(typeof req.body.phone != 'string') ? (member.phone = req.body.phone) : (member.phone = req.body.phone.trim());
	}
	if(req.body.email != undefined){
		(typeof req.body.email != 'string') ? (member.email = req.body.email) : (member.email = req.body.email.trim());
	}
	if(req.body.headImgUrl != undefined){
		(typeof req.body.headImgUrl != 'string') ? (member.headImgUrl = req.body.headImgUrl) : (member.headImgUrl = req.body.headImgUrl.trim());
	}
	if(req.body.fansNum != undefined){
		(typeof req.body.fansNum != 'string') ? (member.fansNum = req.body.fansNum) : (member.fansNum = req.body.fansNum.trim());
	}
	if(req.body.createTime != undefined){
		(typeof req.body.createTime != 'string') ? (member.createTime = req.body.createTime) : (member.createTime = req.body.createTime.trim());
	}
	if(req.body.updateTime != undefined){
		(typeof req.body.updateTime != 'string') ? (member.updateTime = req.body.updateTime) : (member.updateTime = req.body.updateTime.trim());
	}
	if(req.body.bak1 != undefined){
		(typeof req.body.bak1 != 'string') ? (member.bak1 = req.body.bak1) : (member.bak1 = req.body.bak1.trim());
	}
	if(req.body.bak2 != undefined){
		(typeof req.body.bak2 != 'string') ? (member.bak2 = req.body.bak2) : (member.bak2 = req.body.bak2.trim());
	}
	if(req.body.bak3 != undefined){
		(typeof req.body.bak3 != 'string') ? (member.bak3 = req.body.bak3) : (member.bak3 = req.body.bak3.trim());
	}
	if(req.body.bak4 != undefined){
		(typeof req.body.bak4 != 'string') ? (member.bak4 = req.body.bak4) : (member.bak4 = req.body.bak4.trim());
	}
	if(req.body.bak5 != undefined){
		(typeof req.body.bak5 != 'string') ? (member.bak5 = req.body.bak5) : (member.bak5 = req.body.bak5.trim());
	}
	return member;
};

member.initGetReq = function(req){
	var member = {};
	if(req.query.id != undefined){	
		(typeof req.query.id != 'string') ? (member.id = req.query.id) : (member.id = req.query.id.trim());
	}
	if(req.query.username != undefined){	
		(typeof req.query.username != 'string') ? (member.username = req.query.username) : (member.username = req.query.username.trim());
	}
	if(req.query.password != undefined){	
		(typeof req.query.password != 'string') ? (member.password = req.query.password) : (member.password = req.query.password.trim());
	}
	if(req.query.phone != undefined){	
		(typeof req.query.phone != 'string') ? (member.phone = req.query.phone) : (member.phone = req.query.phone.trim());
	}
	if(req.query.email != undefined){	
		(typeof req.query.email != 'string') ? (member.email = req.query.email) : (member.email = req.query.email.trim());
	}
	if(req.query.headImgUrl != undefined){	
		(typeof req.query.headImgUrl != 'string') ? (member.headImgUrl = req.query.headImgUrl) : (member.headImgUrl = req.query.headImgUrl.trim());
	}
	if(req.query.fansNum != undefined){	
		(typeof req.query.fansNum != 'string') ? (member.fansNum = req.query.fansNum) : (member.fansNum = req.query.fansNum.trim());
	}
	if(req.query.createTime != undefined){	
		(typeof req.query.createTime != 'string') ? (member.createTime = req.query.createTime) : (member.createTime = req.query.createTime.trim());
	}
	if(req.query.updateTime != undefined){	
		(typeof req.query.updateTime != 'string') ? (member.updateTime = req.query.updateTime) : (member.updateTime = req.query.updateTime.trim());
	}
	if(req.query.bak1 != undefined){	
		(typeof req.query.bak1 != 'string') ? (member.bak1 = req.query.bak1) : (member.bak1 = req.query.bak1.trim());
	}
	if(req.query.bak2 != undefined){	
		(typeof req.query.bak2 != 'string') ? (member.bak2 = req.query.bak2) : (member.bak2 = req.query.bak2.trim());
	}
	if(req.query.bak3 != undefined){	
		(typeof req.query.bak3 != 'string') ? (member.bak3 = req.query.bak3) : (member.bak3 = req.query.bak3.trim());
	}
	if(req.query.bak4 != undefined){	
		(typeof req.query.bak4 != 'string') ? (member.bak4 = req.query.bak4) : (member.bak4 = req.query.bak4.trim());
	}
	if(req.query.bak5 != undefined){	
		(typeof req.query.bak5 != 'string') ? (member.bak5 = req.query.bak5) : (member.bak5 = req.query.bak5.trim());
	}
	return member;
};


module.exports = member;
